package com.file_.BufferedReaderAndWriter_;

import java.io.BufferedWriter;
import java.io.FileWriter;

// 使用BufferedWriter将“hello,你好”写入到文件中
public class Demo2 {
    public static void main(String[] args) throws Exception {
        String filePath = "D:\\A_Test\\buf_write.txt";
        // 1、创建对象
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath));
        /* 若想采用追加模式，true是加在节点流上：
           BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath, true));
        */
        // 2、写入
        bufferedWriter.write("hello,你好");
        // 3、插入一个和系统相关的换行，美观
        bufferedWriter.newLine();
        bufferedWriter.write("hello,你好2");
        // 4、关闭处理流即可
        bufferedWriter.close();
    }
}
